package com.cssw.fyzb.busi.api.video;

import com.cssw.fyzb.busi.service.im.ImService;
import com.cssw.fyzb.busi.service.video.VideoService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 查询喜欢的视频列表
 *
 * @author YangYiQun
 */
@Function(description = "添加视频评论", parameters = {
        @Parameter(name = "videoId", type = Type.Integer, description = "视频标识", required = true),
        @Parameter(name = "userId", type = Type.Integer, description = "用户标识", required = true),
        @Parameter(name = "content", type = Type.Integer, description = "内容", required = true),
        @Parameter(name = "replyCommentId", type = Type.Integer, description = "回复评论标识", required = false),
})
@Component
public class AddVideoComment implements Action {

    @Autowired
    private VideoService videoService;

    @Autowired
    private ImService imService;

    private static final Logger logger = LoggerFactory.getLogger(AddVideoComment.class);

    @Override
    public Response execute(Request request) throws Exception {
        Long videoId = request.getLong("videoId");
        Long userId = request.getLong("userId");
        Long replyCommentId = request.getLong("replyCommentId");
        String content = request.getString("content");
        try {
            Long commentId = videoService.addComment(userId, videoId, replyCommentId, content);

            imService.sendAddCommentMsg(userId, commentId);
            return Response.success();
        } catch (Exception e) {
            logger.info("", e);
            return Response.fail("操作异常");
        }
    }

}
